package com.bee.common.tools.view;

import java.util.Random;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;

public class RandomGeneratorUtils {
	
	/**
	 * 
	 * @return 6位数字的随机数
	 */
	public static String generate6Num() {
		int[] array = {0,1,2,3,5,6,7,8,9};
		Random rand = new Random();
		for (int i = 9; i > 1; i--) {
		    int index = rand.nextInt(i);
		    int tmp = array[index];
		    array[index] = array[i - 1];
		    array[i - 1] = tmp;
		}
		int result = 0;
		for(int i = 0; i < 6; i++)
		    result = result * 10 + array[i];
		String num=String.format("%06d",result);
		return num;
	}

	public static String generateNum(String prefixStr, String suffixStr, int dight) {
		int[] array = {0,1,2,3,5,6,7,8,9};
		Random rand = new Random();
		for (int i = 9; i > 1; i--) {
		    int index = rand.nextInt(i);
		    int tmp = array[index];
		    array[index] = array[i - 1];
		    array[i - 1] = tmp;
		}
		int result = 0;
		for(int i = 0; i < dight; i++)
		    result = result * 10 + array[i];
		String num=String.format("%0"+dight+"d",result);
		return StringUtils.defaultIfEmpty(prefixStr,"")+num+StringUtils.defaultIfEmpty(suffixStr,"");
	}
	
	
	public static String generateNum(int dight) {
		return generateNum(null,null,dight);
	}
	
	public static String generateUUID(){
		return UUID.randomUUID().toString().replace("-", "");
	}

}
